import { defineStore } from "pinia";
import {registerItem} from '@/network/register'
import {
  getRegisteredItemsByAthleteId,
  removeRegister
} from '@/network/register'
const useRegisterStore = defineStore('register', {
  state: () => ({
    registeredItems:[]
  }),
  actions: {
    async registerItemAction(sportId:number,athleteId:number) {
      await registerItem(sportId, athleteId)
      this.getRegisteredItemsByAthleteIdAction(athleteId)
    },
    async getRegisteredItemsByAthleteIdAction(athleteId: number) {
      const res = await getRegisteredItemsByAthleteId(athleteId)
      this.registeredItems = res.data.list
    },
    async removeRegisterAction(sportId: number, athleteId: number) {
      await removeRegister(sportId, athleteId)
      this.getRegisteredItemsByAthleteIdAction(athleteId)
      
    }
  }
})

export default useRegisterStore